package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.constant.MessageConstant;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Menu;
import com.itheima.health.pojo.Role;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.service.UserService;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileOutputStream;
import java.util.*;

@Controller
@ResponseBody
@RequestMapping("/user")
public class UserController {

    @Reference
    UserService userService;

    @RequestMapping("/getUsername")
    public Result getUsername() {
        org.springframework.security.core.userdetails.User user = (org.springframework.security.core.userdetails.User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        com.itheima.health.pojo.User user1 = userService.findUserByUsername(user.getUsername());
        List<Map<String,Object>> list = new ArrayList<>();

//        for (Role role : user1.getRoles()) {
//            LinkedHashSet<Menu> menus = role.getMenus();
//            for (Menu menu : menus) {
//                HashMap<String, Object> map = new HashMap<>();
//                if(menu.getParentMenuId()==null){
//                    map.put()
//                }
//            }
//        }
        return new Result(true, MessageConstant.GET_USERNAME_SUCCESS, user1);
    }
}

//    "menus":[
//            {"children":[],"description":null,"icon":"fa-user-md","id":1,"linkUrl":null,"name":"会员管理","parentMenuId":null,"path":"2","priority":1,"roles":[]},
//    {"children":[],"description":null,"icon":null,"id":2,"linkUrl":"member.html","name":"会员档案","parentMenuId":1,"path":"/2-1","priority":1,"roles":[]},
//    {"children":[],"description":null,"icon":null,"id":3,"linkUrl":null,"name":"体检上传","parentMenuId":1,"path":"/2-2","priority":2,"roles":[]},
//    {"children":[],"description":null,"icon":null,"id":4,"linkUrl":null,"name":"会员统计","parentMenuId":1,"path":"/2-3","priority":3,"roles":[]}],
//            "name":"健康管理师",
//            "permissions":[{"description":null,"id":4,"keyword":"CHECKITEM_QUERY","name":"查询检查项","roles":[]},
//    {"description":null,"id":8,"keyword":"CHECKGROUP_QUERY","name":"查询检查组","roles":[]},
//    {"description":null,"id":3,"keyword":"CHECKITEM_EDIT","name":"编辑检查项","roles":[]},
//    {"description":null,"id":7,"keyword":"CHECKGROUP_EDIT","name":"编辑检查组","roles":[]},
//    {"description":null,"id":10,"keyword":"SETMEAL_DELETE","name":"删除套餐","roles":[]},
//    {"description":null,"id":13,"keyword":"ORDERSETTING","name":"预约设置","roles":[]},
//    {"description":null,"id":11,"keyword":"SETMEAL_EDIT","name":"编辑套餐","roles":[]},
//    {"description":null,"id":12,"keyword":"SETMEAL_QUERY","name":"查询套餐","roles":[]},
//    {"description":null,"id":9,"keyword":"SETMEAL_ADD","name":"新增套餐","roles":[]},
//    {"description":null,"id":5,"keyword":"CHECKGROUP_ADD","name":"新增检查组","roles":[]}
//            ,{"description":null,"id":14,"keyword":"REPORT_VIEW","name":"查看统计报表","roles":[]},
//    {"description":null,"id":1,"keyword":"CHECKITEM_ADD","name":"新增检查项","roles":[]},
//    {"description":null,"id":6,"keyword":"CHECKGROUP_DELETE","name":"删除检查组","roles":[]}],

